package com.ruoyi.baidu.service.impl;

import com.ruoyi.baidu.service.AlgorithmTypeRepository;
import com.ruoyi.system.api.domain.AlgorithmType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AlgorithmTypeService {

    @Autowired
    private AlgorithmTypeRepository algorithmTypeRepository;

    @Value("${spring.elasticsearch.page}")
    private int page;
    @Value("${spring.elasticsearch.size}")
    private int size;

    public Iterable<AlgorithmType> findAll() {
        return algorithmTypeRepository.findAll();
    }

    public void deleteAll() {
        algorithmTypeRepository.deleteAll();
    }

    public AlgorithmType save(AlgorithmType algorithmType) {
        return algorithmTypeRepository.save(algorithmType);
    }

    public List<AlgorithmType> search(String keyword) {
        Pageable pageable = PageRequest.of(page, size);
        return algorithmTypeRepository.findByAlgorithmNameOrDescription(keyword, keyword, pageable).getContent();
    }
}
